﻿CREATE Procedure [dbo].[sec_ListWhere]
	@Filter nvarchar(1024)
As

DECLARE @SQL nvarchar(1024)

IF NOT ISNULL(@Filter,'') IN ('0','')
	SET @SQL = 'SELECT 
LoanID,
UsixID,
U,
Name,
CONVERT(varchar(255),SSN)SSN,
VIN,
Dealer,
Status,
ContractHolder
 FROM vsec_ListWhere WHERE '+@Filter+
CASE WHEN dbo.IsContractHolder()>0 OR 1=1 THEN '' ELSE
'
UNION ALL
SELECT LoanID,UsixID,0,Name,SSN,VIN,Dealer,Status,''''
FROM AFC.dbo.vsec_ListWhere_MotoBank WHERE '+@Filter
END
ELSE
	SET @SQL = 'SELECT TOP 0 * FROM AFC.dbo.vsec_ListWhere_MotoBank'

--RAISERROR('%s',16,1,@Filter)
EXEC(@SQL)



